package com.utf999.qiangmanger.dao.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Component;

import com.utf999.qiangmanger.dao.AbstractRelationalDBDAO;
import com.utf999.qiangmanger.dao.iface.IStorefrontDAO;
import com.utf999.qiangmanger.entity.orm.StorefrontEntity;
import com.utf999.qiangmanger.exception.BizException;
import com.utf999.qiangmanger.exception.ResponseCode;

/**
 * @author yinwenjie
 *
 */
@Component("StorefrontDAOImpl")
public class StorefrontDAOImpl extends AbstractRelationalDBDAO<StorefrontEntity> implements IStorefrontDAO {

	/* (non-Javadoc)
	 * @see com.utf999.qiangmanger.dao.AbstractRelationalDBDAO#getEntityClass()
	 */
	@Override
	protected Class<StorefrontEntity> getEntityClass() {
		return StorefrontEntity.class;
	}

	//TODO 数据库未进行索引优化
	/* (non-Javadoc)
	 * @see com.utf999.qiangmanger.dao.iface.IStorefrontDAO#queryStorefrontList(java.lang.String, java.lang.Integer)
	 */
	@Override
	public List<StorefrontEntity> queryStorefrontList(String companyid , Integer status) throws BizException {
		HashMap<String, Object> condition = new HashMap<String, Object>();
		condition.put("companyuid", companyid);
		if(status != null) {
			condition.put("status", status);
		}
		
		List<StorefrontEntity> results = null;
		try {
			results = this.queryByHqlFile("IStorefrontDAO.queryStorefrontList", condition);
		} catch (Exception e) {
			throw new BizException(e.getMessage(), ResponseCode.E501);
		}
		
		return results;
	}

	/* (non-Javadoc)
	 * @see com.utf999.qiangmanger.dao.iface.IStorefrontDAO#queryStorefrontByuserid(java.lang.String)
	 */
	@Override
	public StorefrontEntity queryStorefrontByuserid(String adminuserid) throws BizException {
		HashMap<String, Object> condition = new HashMap<String, Object>();
		condition.put("adminuserid", adminuserid);
		List<StorefrontEntity> stores = this.queryByHqlFile("ICompanyDAO.queryStorefrontByuserid", condition);
		if(stores == null || stores.size() == 0) {
			return null;
		}
		
		return stores.get(0);
	}
}
